//封装页面方法

"use strict";

//对象方法
!(function($) {
    var webappWin = {};
    webappWin = {
        a: 10,
        init: function() {
            console.log('初始化');
            webappWin.add();
        },
        add: function() {
            webappWin.a = 20;
            $('body').append('<p>hello world</p>');
            $('.btn').click(function() {
                //不生效
                console.log('btn click')
                //不生效
            })
            //不生效
        }
    };
    webappWin.init();
}
)(jQuery)

//原型链方法,通过new关键字去调用定义的方法
!(function($) {
    function h5page() {
    }
    ;h5page.prototype = {
        test: function() {
            $('.pLine').click(function() {
                console.log('p click');
            });
            //return this;
        },
        init: function() {
            h5page.prototype.test();
        }
    };
    new h5page().init();
}
)(jQuery);

//封装插件

!(function($) {
    $.fn.setColor = function(opt) {
        var set = false;
        if (set) {
            set = false;
            return;
        } else {
            this.addClass('active');
            set = true;
        }
        //this.css({color:opt.color})

    }
    ;
}
)(jQuery)

$('.btn-2').click(function() {
    $(this).setColor();
});

!(function() {
    var ecDoApp = {
        init: function() {
            this.handleClick();
            this.setColor();
            this.setFont();
            this.choose();
            this.checkTel();
        },
        setColor:function(){
        	document.getElementsByClassName('btn-4')[0].addEventListener('click',function(){
        		ecDo.css(this,{color:'green'});
        	});
        	//setColor();
        },

        handleClick: function() {
            document.getElementsByClassName('btn-3')[0].addEventListener('click', function() {
                ecDo.toggleClass(this,'active');
            })
        },
        setFont:function(){
        	ecDo.setFontSize(750);
        },
        choose:function(){
        	var btnsParent=document.getElementsByClassName('btns')[0];
        	var btns=btnsParent.getElementsByTagName('button');
        	// btns.addEventListener('click',function(){
        	// 	console.log(this);
        	// })
        	var inner='';
        	var index=0;
        	for(var i=0;i<btns.length;i++){
        		btns[i].index=i;
        		btns[i].addEventListener('click',function(e){
        			//console.log(this.innerHTML);
        			inner=this.innerHTML;
        			console.log(e);
        			console.log(inner,e.target.index)
        		});
        	};
        	
        },
        checkTel:function(){
        	var tel=13438377532;
        	console.log(ecDo.checkType(tel,'phone'));
        }
    }
    ecDoApp.init();
}
)()
